package com.yourenbang.lingyun.transaction.web.controller.fund;

import com.yourenbang.lingyun.core.base.controller.BaseController;
import com.yourenbang.lingyun.core.base.interceptor.ExcludeInterceptor;
import com.yourenbang.lingyun.core.message.Request;
import com.yourenbang.lingyun.core.message.Result;
import com.yourenbang.lingyun.core.model.vo.PageVO;
import com.yourenbang.lingyun.core.util.KLog;
import com.yourenbang.lingyun.transaction.web.domain.dto.fund.IncomeStatisticsDetailRequest;
import com.yourenbang.lingyun.transaction.web.domain.dto.fund.IncomeStatisticsDetailResponse;
import com.yourenbang.lingyun.transaction.web.domain.dto.fund.IncomeStatisticsTotalRequest;
import com.yourenbang.lingyun.transaction.web.domain.dto.fund.IncomeStatisticsTotalResponse;
import com.yourenbang.lingyun.transaction.web.service.fund.FundService;
import com.yourenbang.transaction.api.model.dto.TopupApplyDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/transaction/income")
public class FundController extends BaseController {

    @Autowired
    private FundService fundService;

    @ExcludeInterceptor
    @PostMapping(value = "/statistics/total")
    public Result<IncomeStatisticsTotalResponse> statisticsTotal(@Validated @RequestBody Request<IncomeStatisticsTotalRequest> request, BindingResult br) {
        if (br.hasErrors()) {
            return checkParamError(br);
        }
        KLog.info("[收益统计（按月按天）]:{}", request);

        return fundService.statisticsTotal(request.getData());
    }

    @ExcludeInterceptor
    @PostMapping(value = "/statistics/detail")
    public Result<PageVO> statisticsDetail(@Validated @RequestBody Request<IncomeStatisticsDetailRequest> request, BindingResult br) {
        if (br.hasErrors()) {
            return checkParamError(br);
        }
        KLog.info("[收益统计明细]:{}", request);
        return fundService.statisticsDetail(request.getData());
    }
}
